﻿namespace HRM.CORE
{

    using APP.HELPER.Data.Helper;
    using Extra.ERP;
    using System; using Extra.ERP;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;

    public class HRM_PROCESS_ADVANCE
    {
        private Guid m_AdvanceID;
        private DateTime m_Date;
        private string m_EmployeeCode;
        private decimal m_Money;
        private string m_Person;
        private string m_Reason;

        public HRM_PROCESS_ADVANCE()
        {
            this.m_AdvanceID = Guid.Empty;
            this.m_EmployeeCode = "";
            this.m_Reason = "";
            this.m_Date = DateTime.Now;
            this.m_Money = 0M;
            this.m_Person = "";
        }

        public HRM_PROCESS_ADVANCE(Guid AdvanceID, string EmployeeCode, string Reason, DateTime Date, decimal Money, string Person)
        {
            this.m_AdvanceID = AdvanceID;
            this.m_EmployeeCode = EmployeeCode;
            this.m_Reason = Reason;
            this.m_Date = Date;
            this.m_Money = Money;
            this.m_Person = Person;
        }

        public string Delete()
        {
            string[] myParams = new string[] { "@AdvanceID" };
            object[] myValues = new object[] { this.m_AdvanceID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("HRM_PROCESS_ADVANCE_Delete", myParams, myValues);
        }

        public string Delete(Guid AdvanceID)
        {
            string[] myParams = new string[] { "@AdvanceID" };
            object[] myValues = new object[] { AdvanceID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("HRM_PROCESS_ADVANCE_Delete", myParams, myValues);
        }

        public string Delete(SqlConnection myConnection, Guid AdvanceID)
        {
            string[] myParams = new string[] { "@AdvanceID" };
            object[] myValues = new object[] { AdvanceID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "HRM_PROCESS_ADVANCE_Delete", myParams, myValues);
        }

        public string Delete(SqlTransaction myTransaction, Guid AdvanceID)
        {
            string[] myParams = new string[] { "@AdvanceID" };
            object[] myValues = new object[] { AdvanceID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "HRM_PROCESS_ADVANCE_Delete", myParams, myValues);
        }

        public string DeleteByMonth(string EmployeeCode, int Month, int Year)
        {
            string[] myParams = new string[] { "@EmployeeCode", "@Month", "@Year" };
            object[] myValues = new object[] { EmployeeCode, Month, Year };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("HRM_PROCESS_ADVANCE_DeleteByMonth", myParams, myValues);
        }

        public bool Exist(Guid AdvanceID)
        {
            bool hasRows = false;
            string[] myParams = new string[] { "@AdvanceID" };
            object[] myValues = new object[] { AdvanceID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("HRM_PROCESS_ADVANCE_Get", myParams, myValues);
            if (reader != null)
            {
                hasRows = reader.HasRows;
                reader.Close();
                helper.Close();
                reader = null;
            }
            return hasRows;
        }

        public string Get(Guid AdvanceID)
        {
            string str = "";
            string[] myParams = new string[] { "@AdvanceID" };
            object[] myValues = new object[] { AdvanceID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("HRM_PROCESS_ADVANCE_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_AdvanceID = reader.GetGuid(reader.GetOrdinal("AdvanceID"));
                    this.m_EmployeeCode = Convert.ToString(reader["EmployeeCode"]);
                    this.m_Reason = Convert.ToString(reader["Reason"]);
                    this.m_Date = Convert.ToDateTime(reader["Date"]);
                    this.m_Money = Convert.ToDecimal(reader["Money"]);
                    this.m_Person = Convert.ToString(reader["Person"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public string Get(SqlConnection myConnection, Guid AdvanceID)
        {
            string str = "";
            string[] myParams = new string[] { "@AdvanceID" };
            object[] myValues = new object[] { AdvanceID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myConnection, "HRM_PROCESS_ADVANCE_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_AdvanceID = reader.GetGuid(reader.GetOrdinal("AdvanceID"));
                    this.m_EmployeeCode = Convert.ToString(reader["EmployeeCode"]);
                    this.m_Reason = Convert.ToString(reader["Reason"]);
                    this.m_Date = Convert.ToDateTime(reader["Date"]);
                    this.m_Money = Convert.ToDecimal(reader["Money"]);
                    this.m_Person = Convert.ToString(reader["Person"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public string Get(SqlTransaction myTransaction, Guid AdvanceID)
        {
            string str = "";
            string[] myParams = new string[] { "@AdvanceID" };
            object[] myValues = new object[] { AdvanceID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myTransaction, "HRM_PROCESS_ADVANCE_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_AdvanceID = reader.GetGuid(reader.GetOrdinal("AdvanceID"));
                    this.m_EmployeeCode = Convert.ToString(reader["EmployeeCode"]);
                    this.m_Reason = Convert.ToString(reader["Reason"]);
                    this.m_Date = Convert.ToDateTime(reader["Date"]);
                    this.m_Money = Convert.ToDecimal(reader["Money"]);
                    this.m_Person = Convert.ToString(reader["Person"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public DataTable GetAllList()
        {
            int level = MyLogin.Level;
            string code = MyLogin.Code;
            string[] myParams = new string[] { "@Level", "@Code" };
            object[] myValues = new object[] { level, code };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteDataTable("HRM_PROCESS_ADVANCE_GetAllList", myParams, myValues);
        }

        public DataTable GetAllListByDays(DateTime BeginDate, DateTime EndDate)
        {
            int level = MyLogin.Level;
            string code = MyLogin.Code;
            string[] myParams = new string[] { "@Level", "@Code", "@BeginDate", "@EndDate" };
            object[] myValues = new object[] { level, code, BeginDate, EndDate };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteDataTable("HRM_PROCESS_ADVANCE_GetAllListByDays", myParams, myValues);
        }

        public DataTable GetList()
        {
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteDataTable("HRM_PROCESS_ADVANCE_GetList");
        }

        public DataTable GetListByDays(string EmployeeCode, DateTime BeginDate, DateTime EndDate)
        {
            string[] myParams = new string[] { "@EmployeeCode", "@BeginDate", "@EndDate" };
            object[] myValues = new object[] { EmployeeCode, BeginDate, EndDate };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteDataTable("HRM_PROCESS_ADVANCE_GetListByDays", myParams, myValues);
        }

        public DataTable GetListByEmployee(string EmployeeCode)
        {
            string[] myParams = new string[] { "@EmployeeCode" };
            object[] myValues = new object[] { EmployeeCode };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteDataTable("HRM_PROCESS_ADVANCE_GetListByEmployee", myParams, myValues);
        }

        public DataTable GetListByMonth(string EmployeeCode, int Month, int Year)
        {
            string[] myParams = new string[] { "@EmployeeCode", "@Month", "@Year" };
            object[] myValues = new object[] { EmployeeCode, Month, Year };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteDataTable("HRM_PROCESS_ADVANCE_GetListByMonth", myParams, myValues);
        }

        public string Insert()
        {
            string[] myParams = new string[] { "@AdvanceID", "@EmployeeCode", "@Reason", "@Date", "@Money", "@Person" };
            object[] myValues = new object[] { this.m_AdvanceID, this.m_EmployeeCode, this.m_Reason, this.m_Date, this.m_Money, this.m_Person };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("HRM_PROCESS_ADVANCE_Insert", myParams, myValues);
        }

        public string Insert(SqlTransaction myTransaction)
        {
            string[] myParams = new string[] { "@AdvanceID", "@EmployeeCode", "@Reason", "@Date", "@Money", "@Person" };
            object[] myValues = new object[] { this.m_AdvanceID, this.m_EmployeeCode, this.m_Reason, this.m_Date, this.m_Money, this.m_Person };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "HRM_PROCESS_ADVANCE_Insert", myParams, myValues);
        }

        public string Insert(Guid AdvanceID, string EmployeeCode, string Reason, DateTime Date, decimal Money, string Person)
        {
            string[] myParams = new string[] { "@AdvanceID", "@EmployeeCode", "@Reason", "@Date", "@Money", "@Person" };
            object[] myValues = new object[] { AdvanceID, EmployeeCode, Reason, Date, Money, Person };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("HRM_PROCESS_ADVANCE_Insert", myParams, myValues);
        }

        public string Insert(SqlConnection myConnection, Guid AdvanceID, string EmployeeCode, string Reason, DateTime Date, decimal Money, string Person)
        {
            string[] myParams = new string[] { "@AdvanceID", "@EmployeeCode", "@Reason", "@Date", "@Money", "@Person" };
            object[] myValues = new object[] { AdvanceID, EmployeeCode, Reason, Date, Money, Person };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "HRM_PROCESS_ADVANCE_Insert", myParams, myValues);
        }

        public string Insert(SqlTransaction myTransaction, Guid AdvanceID, string EmployeeCode, string Reason, DateTime Date, decimal Money, string Person)
        {
            string[] myParams = new string[] { "@AdvanceID", "@EmployeeCode", "@Reason", "@Date", "@Money", "@Person" };
            object[] myValues = new object[] { AdvanceID, EmployeeCode, Reason, Date, Money, Person };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "HRM_PROCESS_ADVANCE_Insert", myParams, myValues);
        }

        public string NewID()
        {
            return SqlHelper.GenCode("HRM_PROCESS_ADVANCE", "JobCode", "CV");
        }

        public string Update()
        {
            string[] myParams = new string[] { "@AdvanceID", "@EmployeeCode", "@Reason", "@Date", "@Money", "@Person" };
            object[] myValues = new object[] { this.m_AdvanceID, this.m_EmployeeCode, this.m_Reason, this.m_Date, this.m_Money, this.m_Person };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("HRM_PROCESS_ADVANCE_Update", myParams, myValues);
        }

        public string Update(Guid AdvanceID, string EmployeeCode, string Reason, DateTime Date, decimal Money, string Person)
        {
            string[] myParams = new string[] { "@AdvanceID", "@EmployeeCode", "@Reason", "@Date", "@Money", "@Person" };
            object[] myValues = new object[] { AdvanceID, EmployeeCode, Reason, Date, Money, Person };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("HRM_PROCESS_ADVANCE_Update", myParams, myValues);
        }

        public string Update(SqlConnection myConnection, Guid AdvanceID, string EmployeeCode, string Reason, DateTime Date, decimal Money, string Person)
        {
            string[] myParams = new string[] { "@AdvanceID", "@EmployeeCode", "@Reason", "@Date", "@Money", "@Person" };
            object[] myValues = new object[] { AdvanceID, EmployeeCode, Reason, Date, Money, Person };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "HRM_PROCESS_ADVANCE_Update", myParams, myValues);
        }

        public string Update(SqlTransaction myTransaction, Guid AdvanceID, string EmployeeCode, string Reason, DateTime Date, decimal Money, string Person)
        {
            string[] myParams = new string[] { "@AdvanceID", "@EmployeeCode", "@Reason", "@Date", "@Money", "@Person" };
            object[] myValues = new object[] { AdvanceID, EmployeeCode, Reason, Date, Money, Person };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "HRM_PROCESS_ADVANCE_Update", myParams, myValues);
        }

        [DisplayName("AdvanceID"), Category("Primary Key")]
        public Guid AdvanceID
        {
            get
            {
                return this.m_AdvanceID;
            }
            set
            {
                this.m_AdvanceID = value;
            }
        }

        [Category("Column"), DisplayName("Date")]
        public DateTime Date
        {
            get
            {
                return this.m_Date;
            }
            set
            {
                this.m_Date = value;
            }
        }

        [DisplayName("EmployeeCode"), Category("Column")]
        public string EmployeeCode
        {
            get
            {
                return this.m_EmployeeCode;
            }
            set
            {
                this.m_EmployeeCode = value;
            }
        }

        [DisplayName("Money"), Category("Column")]
        public decimal Money
        {
            get
            {
                return this.m_Money;
            }
            set
            {
                this.m_Money = value;
            }
        }

        [Category("Column"), DisplayName("Person")]
        public string Person
        {
            get
            {
                return this.m_Person;
            }
            set
            {
                this.m_Person = value;
            }
        }

        public string ProductName
        {
            get
            {
                return "Class HRM_PROCESS_ADVANCE";
            }
        }

        public string ProductVersion
        {
            get
            {
                return "1.0.0.0";
            }
        }

        [Category("Column"), DisplayName("Reason")]
        public string Reason
        {
            get
            {
                return this.m_Reason;
            }
            set
            {
                this.m_Reason = value;
            }
        }
    }
}

